<style>
    body {
        background-color: #ffffff;
    }
</style>
<div class="layui-form layuimini-form">
    <input type="hidden" name="id" value="{{.menu.Id}}">
    {{if eq .type 1}}
        <input type="hidden" name="pid" value="0">
    {{else}}
        <div class="layui-form-item">
            <label class="layui-form-label required">父级id</label>
            <div class="layui-input-block">
                <select name="pid" lay-filter="aihao">
                    {{range .menuSelect}}
                        <option value="{{.id}}" {{if .select}}selected{{end}}>{{.name}}</option>
                    {{end}}
                </select>
            </div>
        </div>
    {{end}}
    <div class="layui-form-item">
        <label class="layui-form-label required">分类名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="分类名不能为空" placeholder="请输入分类名" value="{{.menu.MenuName}}"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">跳转链接</label>
        <div class="layui-input-block">
            <input type="text" name="url" placeholder="" value="{{.menu.MenuUrl}}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序</label>
        <div class="layui-input-block">
            <input type="text" name="sort" lay-verify="required|number" placeholder="" value="{{.menu.Sort}}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标<a class="label label-primary" target="_blank" href="http://www.fontawesome.com.cn/icons-ui/">图标库</a></label>
        <div class="layui-input-block">
            <input type="text" name="icon"  placeholder="" value="{{.menu.Icon}}" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-block">
            <input type="checkbox" {{if eq .menu.IsShow 1}}checked="" {{end}} name="is_show" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            {{if eq .type 1}}
                <input type="radio" name="level" value="1" title="导航" {{if eq .menu.Level 1}}checked="" {{end}}>
            {{else}}
                <input type="radio" name="level" value="2" title="菜单" {{if eq .menu.Level 1}}checked="" {{end}}>
                <input type="radio" name="level" value="3" title="按钮" {{if eq .menu.Level 1}}checked="" {{end}}>
            {{end}}
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            if (data.field.is_show =='on') {
                data.field.is_show = 1
            } else {
                data.field.is_show = 0
            }
            let load;
            $.ajax({
                url: '/admin/api/menu/edit',
                type: "POST",
                data: data.field,
                dataType: "json",
                beforeSend: function () {
                    load = layer.load(2);
                },
                complete: function () {
                    layer.close(load)
                },
                success: function (data) {
                    if (data.code === 1) {
                        // 关闭弹出层
                        layer.msg(data.message, {icon: 1, title: "success"}, function () {
                            let iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    } else {
                        layer.msg(data.message, {icon: 2, title: "error"})
                    }
                }
            });

            return false;
        });

    });
</script>